package wyq.gy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.amap.api.services.core.PoiItem;

import java.util.ArrayList;
import java.util.List;

import wyq.gy.Bean.workerInfo;
import wyq.gy.R;

/**
 *
 */
public class workerListAdapter extends BaseAdapter {

    private List<workerInfo> data;
    private Context context;

    public workerListAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }

    public void setData(List<workerInfo> data) {
        this.data = data;
    }


    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.work_info, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.bindView(position);
        return convertView;
    }


    class ViewHolder {
        TextView workerNameTV;
        TextView phoneTV;
        TextView birthTV;
        TextView starTV;


        public ViewHolder(View view) {
            workerNameTV = (TextView) view.findViewById(R.id.worker_name);
            phoneTV = (TextView) view.findViewById(R.id.worker_phone);
            birthTV = (TextView) view.findViewById(R.id.birth);
            starTV = (TextView) view.findViewById(R.id.star);
        }

        public void bindView(int position) {
            if (position >= data.size())
                return;

            workerInfo item = data.get(position);
            workerNameTV.setText(item.workerName);
            phoneTV.setText(item.phone);
            birthTV.setText(item.birthday);
            starTV.setText(item.star);
        }
    }
}
